//
//  BrandsTableViewCell.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/2.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "BrandsTableViewCell.h"
#import "BrandsContentCollectionViewCell.h"



static NSString *brandsCellID = @"brandsCellID";

@interface BrandsTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (strong, nonatomic) UIView *loadMoreView;
@property (strong, nonatomic) UILabel *loadMoreL;
@property (strong, nonatomic) UIImageView *smallBackIV;

@property (strong, nonatomic) UICollectionView *brandsGoodsCollectionView;

@end

@implementation BrandsTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self.contentView addSubview:self.brandsGoodsCollectionView];
        [self.contentView addSubview:self.loadMoreView];
        [self.loadMoreView addSubview:self.loadMoreL];
        [self.loadMoreView addSubview:self.smallBackIV];
        
    }
    
    return self;

}

- (void)layoutSubviews {
    
    [super layoutSubviews];

    __weak typeof(self) weakSelf = self;
    [self.brandsGoodsCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(Margin);
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-Margin);
        make.top.mas_equalTo(weakSelf.contentView.mas_top);
        make.height.mas_equalTo(jisuan(291));
//        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom).with.offset(-jisuan(60));
    }];
    
    [self.loadMoreView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.contentView.mas_left);
        make.right.mas_equalTo(weakSelf.contentView.mas_right);
        make.top.mas_equalTo(weakSelf.brandsGoodsCollectionView.mas_bottom);
//        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom);
        make.height.mas_equalTo(jisuan(60));
        
    }];
    
    [self.loadMoreL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(weakSelf.loadMoreView.mas_centerX).with.offset(-jisuan(10));
        make.centerY.mas_equalTo(weakSelf.loadMoreView.mas_centerY);
    }];
    
    [self.smallBackIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.loadMoreL.mas_right).with.offset(jisuan(10));
        make.centerY.mas_equalTo(weakSelf.loadMoreView.mas_centerY);
        make.width.mas_equalTo(jisuan(11));
        make.height.mas_equalTo(jisuan(20));
  
    }];

}

#pragma mark -更多品牌点击事件
- (void)loadMoreGestureClick:(UIGestureRecognizer *)recognizer {
    
    NSLog(@"更多品牌点击1111");
    

    
}

#pragma mark -delegate、datasource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 1;

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 5;
    
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    BrandsContentCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:brandsCellID forIndexPath:indexPath];
    
    cell.layer.borderColor = Colorf2f2f2.CGColor;
    cell.layer.borderWidth = jisuan(1);
    
    return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    
    NSLog(@"品牌专区产品点击");
    
}

#pragma mark -lazy
- (UICollectionView *)brandsGoodsCollectionView {
    
    if (!_brandsGoodsCollectionView) {
    
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake(jisuan(170), jisuan(290));
        flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        
        flowLayout.minimumLineSpacing = (WIDTH - 4 * jisuan(170) - 2 * Margin) / 3;
        flowLayout.minimumInteritemSpacing = jisuan(1);
    
        _brandsGoodsCollectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
        _brandsGoodsCollectionView.backgroundColor = WhiteColor;
        
        _brandsGoodsCollectionView.delegate = self;
        _brandsGoodsCollectionView.dataSource = self;
        
        _brandsGoodsCollectionView.showsVerticalScrollIndicator = NO;
        _brandsGoodsCollectionView.showsHorizontalScrollIndicator = NO;
        
        [_brandsGoodsCollectionView registerClass:[BrandsContentCollectionViewCell class] forCellWithReuseIdentifier:brandsCellID];
        
        if (@available (iOS 11.0, *)) {
            
            _brandsGoodsCollectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
        
    }
    
    return _brandsGoodsCollectionView;
    
}

- (UIView *)loadMoreView {
    
    if (!_loadMoreView) {
       
        _loadMoreView = [[UIView alloc] init];
        _loadMoreView.backgroundColor = WhiteColor;
        
    }
    
    return _loadMoreView;
    
}

- (UIImageView *)smallBackIV {
    
    if (!_smallBackIV) {
        
        _smallBackIV = [[UIImageView alloc] init];
        _smallBackIV.image = [UIImage imageNamed:@"smallBackBg1"];
        _smallBackIV.contentMode = UIViewContentModeScaleAspectFit;
        
    }
    
    return _smallBackIV;
}

- (UILabel *)loadMoreL {
    
    if (!_loadMoreL) {
        
        _loadMoreL = [[UILabel alloc] init];
        _loadMoreL.backgroundColor = WhiteColor;
        
        _loadMoreL.text = @"更多商品";
        _loadMoreL.textColor = Color1f89ff;
        _loadMoreL.font = Font(20);
        _loadMoreL.textAlignment = NSTextAlignmentRight;
        
        _loadMoreL.userInteractionEnabled = YES;
        UITapGestureRecognizer *loadMoreGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(loadMoreGestureClick:)];
        [_loadMoreL addGestureRecognizer:loadMoreGesture];
        
    }
    
    return _loadMoreL;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
